﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Dazaza.Framework.Configuration
{
    [XmlRoot("RSConfig")]
    public class RSConfig
    {
        [XmlElement("RSFiles")]
        public RSFiles RSFiles
        {
            get;
            set;
        }

        [XmlElement("Common")]
        public PageReference RSCommon
        {
            get;
            set;
        }

        [XmlArray("Pages")]
        [XmlArrayItem("Page")]
        public List<PageReference> Pages
        {
            get;
            set;
        }

    }

    public class PageReference
    {
        [XmlAttribute("path")]
        public string Path
        {
            get;
            set;
        }

        [XmlElement("Js")]
        public List<FileReference> JsReference
        {
            get;
            set;
        }

        [XmlElement("Css")]
        public List<FileReference> CssReference
        {
            get;
            set;
        }
    }

    public class FileReference
    {
        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }
    }

    public enum HttpType
    {
        Normal,
        Http,
        Https
    }

    public enum PrefixType
    {
        Demo = 0,
        Vss =1,
        Formal =2
    }

    public class RSFiles
    {
        [XmlArray("JsFiles")]
        [XmlArrayItem("File")]
        public List<FileItem> JsFiles
        {
            get;
            set;
        }

        [XmlArray("CssFiles")]
        [XmlArrayItem("File")]
        public List<FileItem> CssFiles
        {
            get;
            set;
        }
    }


    public class ReferenceFiles
    {
        [XmlElement("File")]
        public List<FileItem> InnerFiles
        {
            get;
            set;
        }

        private Dictionary<string, FileItem> _files;
        public Dictionary<string, FileItem> Files
        {
            get
            {
                if (_files == null)
                {
                    if (InnerFiles != null)
                    {
                        _files = new Dictionary<string, FileItem>();
                        foreach (FileItem item in InnerFiles)
                        {
                            if (!_files.Keys.Contains(item.Name))
                            {
                                _files[item.Name] = item;
                            }
                        }
                    }
                }
                return _files;
            }
        }
    }

    public class FileItem
    {
        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("path")]
        public string Path
        {
            get;
            set;
        }

        [XmlAttribute("securePath")]
        public string SecurePath
        {
            get;
            set;
        }

        [XmlAttribute("version")]
        public string Version
        {
            get;
            set;
        }

        [XmlAttribute("pathType")]
        public string InnerPathType
        {
            get;
            set;
        }
        public RSPathType PathType
        {
            get
            {
                //RSPathType rsPathType = RSPathType.Network;
                return (RSPathType)Enum.Parse(typeof(RSPathType), InnerPathType, false);
                //Enum.TryParse<RSPathType>(InnerPathType, out rsPathType);
                //return rsPathType;
            }
        }
    }

    public enum RSPathType
    {
        Local,
        Network
    }

}
